<?php


namespace App\Model;


use App\Common\UploadFile;

class UploadVedioAndCover
{
    /**
     * 上传到系统
     * @param $vedioPath
     * @param $coverPath
     * @return bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function upload($vedioPath, $coverPath)
    {
        $upload = new UploadFile();
        $res = $upload->uploadFile($coverPath, pathinfo($coverPath)['filename']);
        if (is_array($res)) {
            return false;
        }
        $vedioResult = $upload->uploadVedio($vedioPath);
        if (is_array($vedioResult)) {
            list($fileid, $mediaUrl) = $vedioResult;
            $result = HttpRequest::add($mediaUrl, $res, pathinfo($coverPath)['filename']);
            return isset($result['res']) && $result['res'] == 201;
        }
        $upload->delFile(pathinfo($coverPath)['filename']);
        return false;
    }
}